package com.twu.biblioteca;

import java.util.HashMap;
import java.util.Set;

/**
 * Created by isabellali on 4/06/2014.
 */
public class BibliotecaLibrary {

    private HashMap<String,Book> bookLibrary;
    private HashMap<String, Movie> movieLibrary;
    private HashMap<String, User> userLibrary;
    private User currentUser;


    BibliotecaLibrary(){
        bookLibrary = new HashMap<String, Book>();
        Book HeadFirstJava = new Book("Head First Java", "Kathy Sierra & Bert Bates", 2003);
        Book TestDrivenDev = new Book("Test-Driven Development", "Kent Beck", 2003);
        Book AgileDev = new Book("Don't Make Me Think, Revisited", "Steve Krug", 2014);

        bookLibrary.put(HeadFirstJava.getBookName(),HeadFirstJava);
        bookLibrary.put(TestDrivenDev.getBookName(),TestDrivenDev);
        bookLibrary.put(AgileDev.getBookName(),AgileDev);

        movieLibrary = new HashMap<String, Movie>();
        Movie Barefoot = new Movie("Barefoot", 2014, "Andrew Fleming","unrated");
        Movie Robocop = new Movie("Robocop", 2014, "Jose Padilha", "5");
        movieLibrary.put(Barefoot.getName(), Barefoot);
        movieLibrary.put(Robocop.getName(), Robocop);

        userLibrary = new HashMap<String, User>();
        User user = new User("Isabella","11qazwsx","Issy Li","dnflyangle@gmail.com","0452177317");
        userLibrary.put("Isabella", user);
        currentUser = null;
    }

    public Set<String> showBookNameList(){
        return bookLibrary.keySet();
    }

    public HashMap<String,Book> showAllBooksDetails(){
        return bookLibrary;
    }

    public String checkOutMovie(Movie movie){
        return movie.checkOutMovie(movie,movieLibrary);
    }
    public String checkOutBook(Book book){
        return book.checkOutBook(book,bookLibrary);
    }

    public String returnBook(Book book){
        return book.checkOutBook(book,bookLibrary);
    }

    public boolean userLogin(String username, String password){
        if(userLibrary.containsKey(username)){
            User temp= userLibrary.get(username);
            if (temp.getPassword().equals(password)){
                currentUser = temp;
                return true;
            }
            return false;
        }
        return false;
    }

    public User getCurrentUser() {
        return currentUser;
    }

}
